package com.wuseguang.springcloud.controller;


import com.wuseguang.springcloud.Filter.RequestParameterWrapper;
import com.wuseguang.springcloud.entity.Activity;
import com.wuseguang.springcloud.service.ActivityService;
import com.wuseguang.springcloud.util.Result;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;


/**
 * <p>
 * 活动表 前端控制器
 * </p>
 *
 * @author 
 * @since 2020-05-11
 */
@RestController
@RequestMapping("/activity")
public class ActivityController {

    private Logger logger = LoggerFactory.getLogger(this.getClass());
    @Autowired
    private ActivityService activityServiceImpl;
    /**
     * 查询教师发布的所有活动
     * @param title 标题
     * @return
     */
    @RequestMapping("/findActivity")
    public Result findActivity(RequestParameterWrapper request,
                               @RequestParam(value = "title",defaultValue = "",required = false) String title,
                               @RequestParam(value = "indexNo",required = false,defaultValue = "1")Integer indexNo,
                                   @RequestParam(value = "rows",required = false,defaultValue = "20") Integer rows){
        logger.info("查询教师发布的所有活动");
        //教师id
        String teacherId = request.getParam("teacherId");
        return activityServiceImpl.findActivity(title,teacherId,indexNo,rows);
    }

    /**
     * 查询活动信息
     * @param request
     * @param activity 活动信息
     * @return
     */
    @RequestMapping("/addActivity")
    public Result addActivity(RequestParameterWrapper request, Activity activity){
        logger.info("查询活动信息");
        //教师id
        String teacherId = request.getParam("teacherId");
        //学校id
        String schoolId = request.getParam("schoolId");
        activity.setTeacherId(Integer.valueOf(teacherId));
        activity.setSchoolId(Integer.valueOf(schoolId));
        return activityServiceImpl.addActivity(activity);
    }

    /**
     * 查询活动报名详情
     * @param request
     * @param id
     * @return
     */
    @RequestMapping("/findEnrolledStudentByActivityId")
    public Result findEnrolledStudentByActivityId(RequestParameterWrapper request,
                                                  @RequestParam(value = "id") Integer id,
                                                  @RequestParam(value = "classId",required = false,defaultValue = "")String classId,
                                                  @RequestParam(value = "quota")Integer quota){
        logger.info("查询活动报名详情");
        return activityServiceImpl.findEnrolledStudentByActivityId(id,classId,quota);
    }

    /**
     *删除活动
     * @param request
     * @param id 活动id
     * @return
     */
    @RequestMapping("/deleteActivityId")
    public Result deleteActivityId(RequestParameterWrapper request,
                                   @RequestParam(value = "id") Integer id){
        logger.info("删除活动");
        return activityServiceImpl.deleteActivityId(id);
    }

}

